home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / System / ScreenDaemon 1.2 / ScreenDaemon cdev / Framework / TControlPanel.cp < prev    next >
Text File  |  1995-05-16  |  6KB  |  270 lines

  1. #ifndef _H_TControlPanel
  2. #include "TControlPanel.h"
  3. #endif
  4.  
  5.    
  6. // CW CDEV Framework, ©1994-95, Matthew E. Axsom, All Rights Reserved
  7. // Original Framework:  Matthew E. Axsom (chewey@top.monad.net)
  8. // Contributions From:    dEVoN Hubbard (TDevon@aol.com)
  9. //                        Greg Landweber (greg@math.harvard.edu)
  10. // -----------------------------------------------------------
  11. // Version History
  12. // -----------------------------------------------------------
  13. // 1.1.1    Released 05/16/95 - mea
  14. //            Default project is now configured to use the stub CDEV code resource.
  15. //                Included stub CDEV in project.
  16. //                Changed ResType of project preferences to 'cDEV'.
  17. //
  18. //            Modified 01/17/95 - mea
  19. //            Added a check for the macDev message before processing results of function/method
  20. //                calls in CDEVMain.c.  This check prevents the return code from runable() from 
  21. //                being interpreted as an error message.  Serious nasty-ness would result if that
  22. //                happened.  Only those CDEV's with 'mach' resources set to something other
  23. //                that 0xFFFF0000 would have encountered this problem.  Thanks to Greg Landweber
  24. //                for finding this bug!
  25.                 
  26. // 1.1        Released 12/08/94 - mea
  27. //            Added more robust error handling so as to conform to Apple's
  28. //                standard cdev error return codes.
  29. //            Added and corrected comments and udated instructions.
  30. //            Also tested compilation under CW5  No problems.
  31.  
  32. // 1.1d2    Internal version - mea
  33. //            Added a Init() message to base class and call it from CDEVMain
  34. //                just after the object is created.  Should ease porting from Think.
  35. //            Added a Close() message to base class and call it from CDEVMain just
  36. //                before we delete the object.  Should ease porting from Think.
  37. //            Eliminated calls to CommandKey() if keyEvtDev is generated via an
  38. //                autoKey event.
  39. //            Changed name of class source files from CDEVClass.c/h to
  40. //                TControlPanel.cp/h.
  41. //            Changed name of starter cdev source from CDEV.c to CDEV.cp.
  42.  
  43. // 1.1d1    Internal version - dth
  44. //            (Modifications for easier porting from Think cdev class
  45. //                projects without losing strengths of Chewey's framework)
  46. //            Changed name of class from cdevObj to TControlPanel.
  47. //            Changed method names to begin w/capital letter.
  48. //            Changed hit() to ItemHit()
  49. //            Changed KeyDown() & CommandKey() to accept short byte value.
  50. //            Changed action() to give short byte value to key methods.
  51. //            Instance variables are now prefixed with an 'f' to indicate
  52. //                they are a member/field variable.
  53.  
  54. // 1.0.1    Released 12/13/94
  55. //            DlgCut() added to cut() method.
  56. //            DlgCopy() added to copy() method.
  57. //            DlgPaste() added to paste() method.
  58. //            DlgDelete() added to clear() method.
  59. //            Note:  The above additions were made to the sample's base class
  60. //           in the original 1.0 distribution, but didn't make it (I'll plead
  61. //            version control problems ;) into the framework's base class.
  62. //            Thanks to dEVoN Hubbard for pointing this out!
  63. //            
  64. // 1.0         Released 12/08/94
  65. //            Initial verison
  66.  
  67. TControlPanel::TControlPanel(short numItems,DialogPtr cp)
  68. {
  69.     fLastItem = numItems;
  70.     fDialog = cp;
  71.  
  72.     // Init() gets called from CDEVMain just after this call
  73. }
  74.  
  75. // sorry, don't have anything to destroy
  76. TControlPanel::~TControlPanel(void)
  77. {
  78.     // close gets called from CDEVMain just before this call
  79. }
  80.  
  81. // provided for compatibility with Think class.
  82. long TControlPanel::Init(void)
  83. {
  84.     return noErr;
  85. }
  86.  
  87. // provided for compatibility with Think class.
  88. long TControlPanel::Close(void)
  89. {
  90.     return noErr;
  91. }
  92.  
  93. // handle actions not related to initing, opening or closing
  94. long TControlPanel::actions(short message,short itemHit)
  95. {
  96.     long    result=0;
  97.     
  98.     switch (message)
  99.         {
  100.         // handle a click
  101.         case hitDev:
  102.             result=ItemHit(itemHit - fLastItem);    // normalize to our values
  103.             break;
  104.         
  105.         // handle a null event by performing any idle time processing
  106.         case nulDev:
  107.             result=Idle();
  108.             break;
  109.             
  110.         // handle user item updates
  111.         case updateDev:
  112.             result=Update();
  113.             break;
  114.         
  115.         // activate things
  116.         case activDev:
  117.             result=Activate();
  118.             break;
  119.         
  120.         // deactivate things
  121.         case deactivDev:
  122.             result=Deactivate();
  123.             break;
  124.         
  125.         // keydown or autokey
  126.         case keyEvtDev:
  127.             // filter out command keys and handle them via commandKey()
  128.  
  129.             if ((fEvent->modifiers & cmdKey) == 0)
  130.                 result = KeyDown((unsigned char) fEvent->message);
  131.             else
  132.                 // avoid processing command keys tied to autoKey events
  133.                 if (fEvent->message != autoKey)
  134.                     result = CommandKey((unsigned char) fEvent->message);
  135.             break;
  136.             
  137.         // undo command from edit menu
  138.         case undoDev:
  139.             result=Undo();
  140.             break;
  141.         
  142.         // cut command from edit menu
  143.         case cutDev:
  144.             result=Cut();
  145.             break;
  146.         
  147.         // copy command from edit menu
  148.         case copyDev:
  149.             result=Copy();
  150.             break;
  151.         
  152.         // paste command from edit menu
  153.         case pasteDev:
  154.             result=Paste();
  155.             break;
  156.         
  157.         // clear command from edit menu
  158.         case clearDev:
  159.             result=Clear();
  160.             break;
  161.         }
  162.     
  163.     return result;
  164. }
  165.  
  166. // handle command keys for normal editing items
  167. long TControlPanel::CommandKey(short theChar)
  168. {
  169.     long    result=0;
  170.     
  171.     switch (theChar) {
  172.         case 'z':    // cmd - z
  173.         case 'Z':
  174.             result=Undo();
  175.             break;
  176.         
  177.         case 'x':    // cmd - x
  178.         case 'X':
  179.             result=Cut();
  180.             break;
  181.         
  182.         case 'c':    // cmd - c
  183.         case 'C':
  184.             result=Copy();
  185.             break;
  186.         
  187.         case 'v':    // cmd - v
  188.         case 'V':
  189.             result=Paste();
  190.             break;
  191.     }
  192.     
  193.     return result;
  194. }
  195.  
  196. // handle a hit in the control panel.  Note lastItem has already been added to itemHit
  197. long TControlPanel::ItemHit(short /*itemHit*/)
  198. {
  199.     return noErr;
  200. }
  201.  
  202. // got a nulDev (nullEvent) message
  203. long TControlPanel::Idle(void)
  204. {
  205.     return noErr;
  206. }
  207.  
  208. // update any user items
  209. long TControlPanel::Update(void)
  210. {
  211.     return noErr;
  212. }
  213.  
  214. // activate items
  215. long TControlPanel::Activate(void)
  216. {
  217.     return noErr;
  218. }
  219.  
  220. // deactivate items
  221. long TControlPanel::Deactivate(void)
  222. {
  223.     return noErr;
  224. }
  225.  
  226. // handle a key down
  227. long TControlPanel::KeyDown(short /*theChar*/)
  228. {
  229.     return noErr;
  230. }
  231.  
  232. // handle an undo
  233. long TControlPanel::Undo(void)
  234. {
  235.     return noErr;
  236. }
  237.  
  238. // handle a cut
  239. long TControlPanel::Cut(void)
  240. {
  241.     DlgCut(fDialog);
  242.     
  243.     return noErr;
  244. }
  245.  
  246. // handle a copy
  247. long TControlPanel::Copy(void)
  248. {
  249.     DlgCopy(fDialog);
  250.     
  251.     return noErr;
  252. }
  253.  
  254. // handle a paste
  255. long TControlPanel::Paste(void)
  256. {
  257.     DlgPaste(fDialog);
  258.  
  259.     return noErr;
  260. }
  261.  
  262. // handle a clear
  263. long TControlPanel::Clear(void)
  264. {
  265.     DlgDelete(fDialog);
  266.     
  267.     return noErr;
  268. }
  269.     
  270.